package com.javasm.utils;

import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.BaseRowModel;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Font;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class ExcelUtil {

    /**
     * 导出 Excel ：一个 sheet，带表头
     *
     * @param response HttpServletResponse
     * @param list 数据 list，每个元素为一个 BaseRowModel
     * @param fileName 导出的文件名
     * @param sheetName 导入文件的 sheet 名
     * @param object 映射实体类，Excel 模型
     */
    public static void writeExcel(HttpServletResponse response, List<? extends BaseRowModel> list, String fileName,
                                  String sheetName, BaseRowModel object) {
//        ExcelWriter writer = new ExcelWriter(getOutputStream(fileName, response), ExcelTypeEnum.XLSX);
//        Sheet sheet = new Sheet(1, 0, object.getClass());
//        sheet.setSheetName(sheetName);
//
//        TableStyle tableStyle = new TableStyle();
//        tableStyle.setTableContentBackGroundColor(IndexedColors.WHITE);
//        Font font = new Font();
//        font.setFontHeightInPoints((short) 9);
//        tableStyle.setTableHeadFont(font);
//        tableStyle.setTableContentFont(font);
//        sheet.setTableStyle(tableStyle);
//
//        writer.write(list, sheet);
//        writer.finish();
    }
}